{% extends "base.html" %}

{% block content %}
<div class="container">
    <h2>文件可见性管理</h2>
    
    <!-- 全局设置 -->
    <div class="card mb-4">
        <div class="card-body">
            <form action="{{ url_for('set_all_visibility') }}" method="POST" class="mb-3">
                <div class="form-check form-switch">
                    <input class="form-check-input" type="checkbox" id="globalVisibility" name="is_public" {% if all_public %}checked{% endif %}>
                    <label class="form-check-label" for="globalVisibility">所有文件全员可见</label>
                </div>
                <button type="submit" class="btn btn-primary mt-2">应用设置</button>
            </form>
        </div>
    </div>

    <!-- 文件列表 -->
    <div class="card">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table">
                    <thead>
                        <tr>
                            <th>文件名</th>
                            <th>上传者</th>
                            <th>学科</th>
                            <th>年级</th>
                            <th>年份</th>
                            <th>可见性</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for file in files %}
                        <tr>
                            <td>{{ file.original_filename }}</td>
                            <td>{{ file.owner.real_name }}</td>
                            <td>{{ file.subject }}</td>
                            <td>{{ file.grade }}</td>
                            <td>{{ file.school_year.year }}年</td>
                            <td>
                                {% if file.is_public %}
                                <span class="badge bg-success">全员可见</span>
                                {% else %}
                                <span class="badge bg-secondary">私有</span>
                                {% endif %}
                            </td>
                            <td>
                                <form action="{{ url_for('toggle_file_visibility', file_id=file.id) }}" method="POST" style="display: inline;">
                                    <button type="submit" class="btn btn-warning btn-sm">
                                        {% if file.is_public %}设为私有{% else %}设为公开{% endif %}
                                    </button>
                                </form>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{% endblock %} 